import wx from 'weixin-js-sdk'

export function deepClone(obj) {
    let result = Array.isArray(obj) ? [] : {}
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            if (typeof obj[key] === 'object' && obj[key] !== null) {
                result[key] = deepClone(obj[key]) // 递归复制
            } else {
                result[key] = obj[key]
            }
        }
    }
    return result
}

//微信授权登录
export function auth() {
    let appId = 'wxe299765eb008147e',
        oldUrl = window.location.href,
        redirect_uri = oldUrl.split('#')[0],
        scope = 'snsapi_base';//snsapi_base 不弹出授权页面，直接跳转，只能获取用户openid  snsapi_userinfo 弹出授权页面，可通过openid拿到昵称、性别、所在地。并且， 即使在未关注的情况下，只要用户授权，也能获取其信息
    window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=1#wechat_redirect`
}

export function getJSSDK() {
wx
}
